package com.ruoyi.zhmk.controller;

import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zhmk.domain.ZhmkAsk;
import com.ruoyi.zhmk.service.IZhmkAskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 人员请假Controller
 * 
 * @author ruoyi
 * @date 2021-06-24
 */
@Api("人员请假信息")
@RestController
@RequestMapping("/zhmk/ask")
public class ZhmkAskController extends BaseController
{
    @Autowired
    private IZhmkAskService zhmkAskService;

    /**
     * 获取人员请假详细信息
     */
    @ApiOperation("获取人员请假详细信息")
    @ApiImplicitParam(name = "id", value = "请假ID", required = true, dataType = "Long", paramType = "path")
    @PreAuthorize("@ss.hasPermi('zhmk:ask:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(zhmkAskService.selectZhmkAskById(id));
    }

    /**
     * 查询人员请假列表
     */
    @PreAuthorize("@ss.hasPermi('zhmk:ask:list')")
    @GetMapping("/list")
    @DataScope(deptAlias = "zhmk_ask")
    public TableDataInfo list(ZhmkAsk zhmkAsk)
    {
        startPage();
        List<ZhmkAsk> list = zhmkAskService.selectZhmkAskList(zhmkAsk);
        return getDataTable(list);
    }

    /**
     * 导出人员请假列表
     */
    @PreAuthorize("@ss.hasPermi('zhmk:ask:export')")
    @Log(title = "人员请假", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ZhmkAsk zhmkAsk)
    {
        List<ZhmkAsk> list = zhmkAskService.selectZhmkAskList(zhmkAsk);
        ExcelUtil<ZhmkAsk> util = new ExcelUtil<ZhmkAsk>(ZhmkAsk.class);
        return util.exportExcel(list, "人员请假数据");
    }

    /**
     * 新增人员请假
     */
    @PreAuthorize("@ss.hasPermi('zhmk:ask:add')")
    @Log(title = "人员请假", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZhmkAsk zhmkAsk)
    {
        return toAjax(zhmkAskService.insertZhmkAsk(zhmkAsk));
    }

    /**
     * 修改人员请假
     */
    @PreAuthorize("@ss.hasPermi('zhmk:ask:edit')")
    @Log(title = "人员请假", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZhmkAsk zhmkAsk)
    {
        return toAjax(zhmkAskService.updateZhmkAsk(zhmkAsk));
    }

    /**
     * 删除人员请假
     */
    @PreAuthorize("@ss.hasPermi('zhmk:ask:remove')")
    @Log(title = "人员请假", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zhmkAskService.deleteZhmkAskByIds(ids));
    }

    /**
     * 审核人员请假
     */
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "请假ID", dataType = "Long"),
        @ApiImplicitParam(name = "roleCode", value = "角色编码", dataType = "String"),
    })
    @PostMapping(value = "/check")
    public AjaxResult check(@RequestBody ZhmkAsk zhmkAsk)
    {
        return toAjax(zhmkAskService.check(zhmkAsk));
    }

    /**
     * 查询人员请假待审核列表
     */
    @GetMapping("/todolist")
    @DataScope(deptAlias = "zhmk_ask")
    public TableDataInfo todolist(ZhmkAsk zhmkAsk)
    {
        startPage();
        List<ZhmkAsk> list = zhmkAskService.selectZhmkAskToDoList(zhmkAsk);
        return getDataTable(list);
    }
}
